package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PinyinUtlis;
import com.ruoyi.common.utils.SysTenantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysApplicationMapper;
import com.ruoyi.system.domain.SysApplication;
import com.ruoyi.system.service.ISysApplicationService;
import com.ruoyi.common.core.text.Convert;

/**
 * 系统应用Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-19
 */
@Service
public class SysApplicationServiceImpl implements ISysApplicationService 
{
    @Autowired
    private SysApplicationMapper sysApplicationMapper;

    /**
     * 查询系统应用
     * 
     * @param appCode 系统应用主键
     * @return 系统应用
     */
    @Override
    public SysApplication selectSysApplicationByAppCode(String appCode)
    {
        return sysApplicationMapper.selectSysApplicationByAppCode(appCode);
    }

    /**
     * 查询系统应用列表
     * 
     * @param sysApplication 系统应用
     * @return 系统应用
     */
    @Override
    public List<SysApplication> selectSysApplicationList(SysApplication sysApplication)
    {
        return sysApplicationMapper.selectSysApplicationList(sysApplication);
    }

    /**
     * 新增系统应用
     * 
     * @param sysApplication 系统应用
     * @return 结果
     */
    @Override
    public int insertSysApplication(SysApplication sysApplication)
    {

        sysApplication.setAppCode(SysTenantUtils.getAppCodePrefix(sysApplication.getAppType())
                + PinyinUtlis.converterToFirstSpell(sysApplication.getAppName()));
        sysApplication.setCreateTime(DateUtils.getNowDate());
        sysApplication.setFreeDate(sysApplication.getIsFree().equals(UserConstants.YES)?0:sysApplication.getFreeDate());
        return sysApplicationMapper.insertSysApplication(sysApplication);
    }

    /**
     * 修改系统应用
     * 
     * @param sysApplication 系统应用
     * @return 结果
     */
    @Override
    public int updateSysApplication(SysApplication sysApplication)
    {
        sysApplication.setUpdateTime(DateUtils.getNowDate());
        sysApplication.setFreeDate(sysApplication.getIsFree().equals(UserConstants.YES)?0:sysApplication.getFreeDate());
        return sysApplicationMapper.updateSysApplication(sysApplication);
    }

    /**
     * 批量删除系统应用
     * 
     * @param appCodes 需要删除的系统应用主键
     * @return 结果
     */
    @Override
    public int deleteSysApplicationByAppCodes(String appCodes)
    {
        return sysApplicationMapper.deleteSysApplicationByAppCodes(Convert.toStrArray(appCodes));
    }

    /**
     * 删除系统应用信息
     * 
     * @param appCode 系统应用主键
     * @return 结果
     */
    @Override
    public int deleteSysApplicationByAppCode(String appCode)
    {
        return sysApplicationMapper.deleteSysApplicationByAppCode(appCode);
    }

    /**
     * 获取所有正常的系统应用
     *
     * @return
     */
    @Override
    public List<SysApplication> getSysApplications() {
        return sysApplicationMapper.getSysApplications();
    }
}